import request from '@/utils/request'

export default {
  get(url, params = {}) {
    return new Promise((resolve, reject) => {
      request({
        url: url,
        method: 'get',
        params: params
      }).then(res => resolve(res)).catch(err => reject(err))
    })
  },
  // insert
  post(url, params = {}) {
    return new Promise((resolve, reject) => {
      request({
        url: url,
        method: 'post',
        data: params
      }).then(res => resolve(res)).catch(err => reject(err))
    })
  },
  // merge
  put(url, params = {}) {
    params._method = 'PUT'
    return new Promise((resolve, reject) => {
      request({
        url: url,
        method: 'post',
        data: params
      }).then(res => resolve(res)).catch(err => reject(err))
    })
  },
  // UPDATE
  patch(url, params = {}) {
    return new Promise((resolve, reject) => {
      request({
        url: url,
        method: 'patch',
        data: params
      }).then(res => resolve(res)).catch(err => reject(err))
    })
  },
  // delete
  delete(url, params = {}) {
    return new Promise((resolve, reject) => {
      request({
        url: url,
        method: 'delete',
        data: params
      }).then(res => resolve(res)).catch(err => reject(err))
    })
  }
}
